﻿using Microsoft.Office.Tools.Ribbon;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QMagicBoxExcel
{
    public partial class Ribbon
    {
        private void Ribbon_Load(object sender, RibbonUIEventArgs e)
        {

        }
        //【功能】单击弹出AI对话人物窗格
        private void BtnChatWithAI_Click(object sender, RibbonControlEventArgs e)
        {
            try
            {
                // 获取 ThisAddIn 实例
                ThisAddIn thisAddIn = Globals.ThisAddIn;

                // 确保有活动文档
                if (thisAddIn.Application.ActiveWorkbook == null)
                {
                    System.Windows.Forms.MessageBox.Show("当前没有打开的文档！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                // 调用切换任务窗格的方法
                thisAddIn.ToggleTaskPaneForActiveWorkbook();

                // 设置任务窗格的宽度为 1080
                var activeDoc = thisAddIn.Application.ActiveWorkbook;
                if (thisAddIn._taskPanes.TryGetValue(activeDoc, out var pane))
                {
                    pane.Width = 1080;
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show($"操作失败: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}